<?php
  class XMLConverter{
  
    function objectToXML($stdClass){
  
      $xml = new XMLWriter();
      $xml->openMemory();

      $this->_addNodeToXML($xml,'root',$stdClass);
      return $xml->outputMemory();
    }
  
    function _addNodeToXML(&$xml,$nodeName,$nodeValue){
    
      if(is_array($nodeValue)){
        $xml->startElement($nodeName);
        foreach($nodeValue as $nodeValueKey => $nodeValueValue){
          $this->_addNodeToXML($xml, $nodeValueKey, $nodeValueValue);
        }
        $xml->endElement();
      }elseif(is_a($nodeValue,'stdClass')){
        $xml->startElement("item");
        foreach($nodeValue as $nodeValueKey => $nodeValueValue){
          $this->_addNodeToXML($xml, $nodeValueKey, $nodeValueValue);
        }
        $xml->endElement();
      }else{
        $xml->writeElement($nodeName,$nodeValue);
      }
    }
  }
?>